#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=110;
int n,root,lc[MAXN],rc[MAXN],fa[MAXN],ans[MAXN];
void work(int i)
{
	int x=root,t;
	while(~rc[x])x=lc[x];
	t=lc[x];
	if(~t&&!(~lc[t])&&!(~rc[t]))x=t;
	ans[i]=x;
	if(x==root)root=lc[root];
	t=fa[x];
	if(~t)lc[t]=lc[x],fa[lc[t]]=t;
	while(~t)swap(lc[t],rc[t]),t=fa[t];
	return;
}
int main()
{
	fa[0]=-1;
	memset(lc,-1,sizeof(lc));
	memset(rc,-1,sizeof(rc));
	n=read();
	for(int i=1;i<=n;++i)
	{
		int x=read();
		if(x<100)lc[x]=i,fa[i]=x;
		else rc[x-100]=i,fa[i]=x-100;
	}
	for(int i=1;i<=n+1;++i)work(i);
	for(int i=n+1;i;--i)printf("%d ",ans[i]);
	puts("");
	return 0;
}
